package com.xh.lesson.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xh.lesson.entity.THouseFunction;
import com.xh.lesson.exception.BusinessException;
import com.xh.lesson.exception.code.BaseResponseCode;
import com.xh.lesson.mapper.THouseFunctiondMapper;
import com.xh.lesson.service.THouseFunctionService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 柴&许
 * @since 2021-06-23
 */
@Service
public class THouseFunctionServiceImpl extends ServiceImpl<THouseFunctiondMapper, THouseFunction> implements THouseFunctionService {

    //通过id查询使用类型（二级）


    @Override
    public THouseFunction selectName(String funname) {
        QueryWrapper<THouseFunction> wrapper = new QueryWrapper<>();
        wrapper.eq("funname",funname);
        THouseFunction function = baseMapper.selectOne(wrapper);
        return function;
    }

    //根据id查询父name功能划分（一级）
    @Override
    public String selectPnameByid(Integer id) {
        Integer parentid = baseMapper.selectById(id).getParentid();

        if (parentid == 0) {
            throw new BusinessException(BaseResponseCode.DATA_ERROR);
        }
        String funPname = baseMapper.selectById(parentid).getFunname();
        return funPname;
    }

    @Override
    public List<THouseFunction> selectFun() {
        QueryWrapper<THouseFunction> wrapper = new QueryWrapper<>();
        wrapper.eq("parentid",0);
        List<THouseFunction> list = baseMapper.selectList(wrapper);
        return list;
    }

    @Override
    public List<THouseFunction> selectFunUse(Integer id) {
        QueryWrapper<THouseFunction> wrapper = new QueryWrapper<>();
        wrapper.eq("parentid",id);
        List<THouseFunction> list = baseMapper.selectList(wrapper);
        return list;
    }
}
